package org.yty.travelagencyredis.service.impl;

import cn.hutool.core.util.IdUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.yty.travelagencyredis.Dao.RouteDao;
import org.yty.travelagencyredis.model.Entity.Route;
import org.yty.travelagencyredis.service.RouteService;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class RouteServiceImpl implements RouteService {
    private final RouteDao routeDao;

    @Override
    public Route getById(Long id) {
        return this.routeDao.selectById(id);
    }

    @Override
    public boolean save(Route route) {
        if (route.getId() == null){
            route.setId(IdUtil.getSnowflakeNextId());
        }
        route.setCreateTime(LocalDateTime.now());
        route.setUpdateTime(LocalDateTime.now());
        return this.routeDao.insert(route);
    }

    @Override
    public boolean update(Route route) {
        route.setUpdateTime(LocalDateTime.now());
        return this.routeDao.updateById(route);
    }

    @Override
    public void removeById(Long id) {
        this.routeDao.deleteById(id);
    }
}
